//
//  HLMineNoteCell.m
//  HLAerospace
//
//  Created by hulian-ios on 17/9/15.
//  Copyright © 2017年 hulian-LB. All rights reserved.
//

#import "HLMineNoteCell.h"
#import <Masonry/Masonry.h>
#import "HLCourseComment.h"
#import "HLMineNote.h"

@interface HLMineNoteCell()

/** authorL  */
@property (nonatomic ,strong) UILabel *title;
/** contentL  */
@property (nonatomic ,strong) UIButton *deleteB;
/** timeL  */
@property (nonatomic ,strong) UIButton *editB;


@end

@implementation HLMineNoteCell


- (UILabel *)title
{
    if (!_title ) {
        _title = [[UILabel alloc] init];
        _title.numberOfLines = 0;
        _title.text = @"航天航空知识简介";
        _title.textColor = HLRGB(60, 60, 60);
        _title.font = [UIFont systemFontOfSize:IS_IPHONE_5 ? 14:(kMainTitleFontSize + 2)];
    }
    return _title;
}


- (UIButton *)deleteB
{
    if (!_deleteB ) {
        _deleteB = [[UIButton alloc]init];
        [_deleteB setImage:[UIImage imageNamed:@"mine_course_delete"] forState:UIControlStateNormal];
        [_deleteB addTarget:self action:@selector(deleteButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _deleteB;
}

- (UIButton *)editB
{
    if (!_editB ) {
        _editB = [[UIButton alloc] init];
        _editB.titleLabel.font = [UIFont systemFontOfSize:14];
        _editB.backgroundColor = kColorMineBlueBG;
        _editB.layer.cornerRadius = 3;
        _editB.clipsToBounds = YES;
        [_editB setTitle:@"编辑" forState:UIControlStateNormal];
        [_editB setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_editB addTarget:self action:@selector(editButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _editB;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setUI];
    }
    return self;
}

- (void)setUI
{
    [self.contentView addSubview:self.title];
    [self.contentView addSubview:self.deleteB];
    [self.contentView addSubview:self.editB];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self configsCons];
}

- (void)configsCons
{
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(15);
        make.centerY.equalTo(self.contentView);
        make.width.equalTo(@(self.width *0.7));
        make.height.equalTo(@(30));
    }];
    
    [self.editB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-20);
        make.centerY.equalTo(self.contentView);
        make.width.equalTo(@(40));
        make.height.equalTo(@(25));
    }];
    
    [self.deleteB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.editB.mas_left).offset(-15);
        make.centerY.equalTo(self.contentView);
        make.width.equalTo(@(40));
        make.height.equalTo(@(30));
    }];
}

- (void)setMineNote:(HLMineNote *)mineNote
{
    _mineNote = mineNote;
    self.title.text = mineNote.course_name;
}

- (void)deleteButtonClick:(UIButton *)button
{
    if ([self.delegate respondsToSelector:@selector(mineNoteCell:didClickEditMineNote:)]) {
        [self.delegate mineNoteCell:self didClickDeleteMineNote:_mineNote];
    }
}

- (void)editButtonClick:(UIButton *)button
{
    if ([self.delegate respondsToSelector:@selector(mineNoteCell:didClickDeleteMineNote:)]) {
        [self.delegate mineNoteCell:self didClickEditMineNote:_mineNote];
    }
}

- (void)setFrame:(CGRect)frame
{
    frame.origin.y += 1;
    frame.size.height = frame.size.height - 1;
    [super setFrame:frame];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}

@end
